// packageA/ProductLicensing/ProductLicensing.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    phonevalue: '',//授权的手机号
    listArr: [],//得到的数据
    time: null,//输入框防抖
    uid2: '',//授权的id
  },
  // 点击授权
  submit() {
    var that = this
    var uid = that.data.uid
    var AuthorizationUserName = that.data.phonevalue
    // console.log(baseJs.api_User + "BusinessAuthorizationManage/"+'?'+"UID="+uid+'&AuthorizationUserName='+AuthorizationUserName);
    wx.request({
      url: baseJs.api_User + "BusinessAuthorizationManage/" + '?' + "UID=" + uid + '&AuthorizationUserName=' + AuthorizationUserName,
      success: (res => {
        var data = res.data
        console.log(res);
        console.log(data);
        if (data.ResultFlag == 0) {
          wx.showToast({
            title: data.ResultMsg,
            icon: "error",
            duration: 2000
          })
        } else {
          wx.showToast({
            title: data.ResultMsg,
            icon: "success",
            duration: 2000
          })
        }
      })
    })
  },
  // 获取授权的手机号
  getPhoneValue(e) {
    clearTimeout(this.data.time)
    this.data.time = setTimeout(() => {
      this.setData({
        phonevalue: e.detail.value
      })
    }, 800);

  },
  // 跳转到商品分类
  goClassfic(e) {
    console.log(e.currentTarget.dataset.id);
    wx.navigateTo({
      url: '/packageA/classification/classification?uid=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      uid: wx.getStorageSync('uid')
    })
    wx.request({
      url: baseJs.api_User + "GetAuthorizationMeBusiness/" + '?' + "UID=" + this.data.uid,
      success: (res => {
        console.log(res);
        if (res.statusCode == 200 && res.data.ResultMsg!="暂无数据") {
          this.setData({
            listArr: res.data.ResultData,
            // phonevalue:res.data.ResultData[0].UserName,
            uid2: res.data.ResultData[0].Uid
          })
        }
        console.log(this.data.listArr);
        console.log(this.data.phonevalue);
      })
    })
    console.log(this.data.uid);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.request({
      url: baseJs.api_User + "GetAuthorizationMeBusiness/" + '?' + "UID=" + this.data.uid,
      success: (res => {
        console.log(res);
        if (res.statusCode == 200  && res.data.ResultMsg!="暂无数据") {
          this.setData({
            listArr: res.data.ResultData,
            // phonevalue:res.data.ResultData[0].UserName,
            uid2: res.data.ResultData[0].Uid
          })
        }
        console.log(this.data.listArr);
        console.log(this.data.phonevalue);
      })
    })
    console.log(this.data.uid);
  },

})